package com.epam.manager.controller;

import java.util.List;

import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;

import org.apache.log4j.Logger;

import com.epam.DAO.BillDAO;
import com.epam.entity.Bill;
import com.epam.entity.Request;
import com.epam.entity.Status;

public class ClosedRequestManagedBean extends RequestController {

	private static Logger log = Logger.getLogger(ClosedRequestManagedBean.class);
	
	private Request request;
	private Bill bill;
	
	private DataModel<Bill> bills;
	private BillDAO billDAO;
	
	private int page = 1;
	
	public ClosedRequestManagedBean() {
		super();
		bills = new ListDataModel<Bill>();
		billDAO = daoFactory.getBillDAO();
	}
	
	public DataModel<Bill> getBills() {
		List<Bill> list = billDAO.getRequestBills(requests.getRowData());
		bills.setWrappedData(list);
		return bills;
	}

	public void setBills(DataModel<Bill> bills) {
		this.bills = bills;
	}

	public Request getRequest() {
		return request;
	}

	public void setRequest(Request request) {
		this.request = request;
	}
	
	public Bill getBill() {
		return bill;
	}

	public void setBill(Bill bill) {
		this.bill = bill;
	}
	
	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}
	
	public void initRequest() {
		request = requests.getRowData();
		log.debug("ClosedRequestManagedBean initRequest " + request);
	}
	
	public void initBill() {
		bill = bills.getRowData();
	}
	
	@Override
	public DataModel<Request> getRequests() {
		requests.setWrappedData(requestDAO.getRequests(Status.CLOSED, Status.CANCELLED));
		return requests;
	}

	public void updateRequest() {
		log.debug("ClosedRequestManagedBean updateRequest " + request);
		requestDAO.update(request);
	}

}
